﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApplication1
{
    class GameList
    {
        private static List<Game> _gameList;
        public static List<Game> gameList
        {
            get { return _gameList; }
            set { _gameList = value; }
        }

        public GameList()
        {
            gameList = new List<Game>();
        }

        public static Game addGame(Game gameObj)
        {

            gameList.Add(gameObj);
            return gameObj;
        }

        public static String removeGame(String gameid)
        {
            foreach (Game game in gameList)
            {
                if (game.getId() == gameid)
                {
                    gameList.Remove(game);
                    return game.getName();
                }
            }
            return null;
        }

        public static Game getGame(String gamestring)
        {
            foreach (Game game in gameList)
            {
                if (game.getId() == gamestring || game.getName() == gamestring)
                {
                    return game;
                }
            }
            return null;
        }

        public static List<Game> getList()
        {
            return gameList;
        }
    }

    class Game
    {
        private string id;
        private String gameName;
        private String gameIP;
        private String username;
        private int maxPlayers;
        private int timeLength;
        private int lives;

        public Game(String name, String IP, String guid, String username, String settings)
        {
            this.id = guid;
            this.gameIP = IP;
            this.gameName = name;
            this.username = username;
            String[] sett = settings.Split('-');
            String aux = "";
            aux = sett[0] == "0" ? "10" : sett[0] == "1" ? "20" : sett[0] == "2" ? "30" : sett[0] == "3" ? "30" : "0";
            maxPlayers = Convert.ToInt32(aux);
            aux = sett[1];
            lives = Convert.ToInt32(aux);
            aux = sett[2];
            timeLength = Convert.ToInt32(aux);
        }

        public String getName()
        {
            return this.gameName;
        }

        public String getIP()
        {
            return this.gameIP;
        }

        public String getId()
        {
            return this.id;
        }

        public int getMaxPlayers()
        {
            return maxPlayers;
        }

        public int getLives()
        {
            return lives;
        }

        public int getTimeLength()
        {
            return timeLength;
        }
    }
}
